<?php
require_once dirname(__FILE__) . '/../../../../test/bootstrap/unit.php';

//Initialize the environment
$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'test', true);

$now_dates = array(
    getdate(strtotime('2010-01-01 00:00:00')),
    getdate(strtotime('2010-01-01 00:15:00')),
    getdate(strtotime('2010-01-01 00:30:00')),
    getdate(strtotime('2010-01-01 00:45:00')),
    getdate(strtotime('2010-01-01 09:00:00'))
);

$tests = array(
    //	Standard cases
    array(
        'info' => 'Run every minute (* * * * *)',
        'job' => array('minute' => '*', 'hour' => '*', 'day_of_month' => '*', 'month' => '*', 'day_of_week' => '*'),
        'now' => $now_dates,
        'expected' => array('2010-01-01 00:01:00', '2010-01-01 00:16:00', '2010-01-01 00:31:00', '2010-01-01 00:46:00', '2010-01-01 09:01:00'),
    ),
    array(
        'info' => 'Run every minute (0-59 0-23 1-31 1-12 0-6)',
        'job' => array('minute' => '0-59', 'hour' => '0-23', 'day_of_month' => '1-31', 'month' => '1-12', 'day_of_week' => '0-6'),
        'now' => $now_dates,
        'expected' => array('2010-01-01 00:01:00', '2010-01-01 00:16:00', '2010-01-01 00:31:00', '2010-01-01 00:46:00', '2010-01-01 09:01:00'),
    ),
    array(
        'info' => 'Run every five minutes (*/5 * * * *)',
        'job' => array('minute' => '*/5', 'hour' => '*', 'day_of_month' => '*', 'month' => '*', 'day_of_week' => '*'),
        'now' => $now_dates,
        'expected' => array('2010-01-01 00:05:00', '2010-01-01 00:20:00', '2010-01-01 00:35:00', '2010-01-01 00:50:00', '2010-01-01 09:05:00'),
    ),
    array(
        'info' => 'Run every five minutes (0-59/5 * * * *)',
        'job' => array('minute' => '0-59/5', 'hour' => '*', 'day_of_month' => '*', 'month' => '*', 'day_of_week' => '*'),
        'now' => $now_dates,
        'expected' => array('2010-01-01 00:05:00', '2010-01-01 00:20:00', '2010-01-01 00:35:00', '2010-01-01 00:50:00', '2010-01-01 09:05:00'),
    ),
    array(
        'info' => 'Run once an hour (30 * * * *)',
        'job' => array('minute' => '30', 'hour' => '*', 'day_of_month' => '*', 'month' => '*', 'day_of_week' => '*'),
        'now' => $now_dates,
        'expected' => array('2010-01-01 00:30:00', '2010-01-01 00:30:00', '2010-01-01 01:30:00', '2010-01-01 01:30:00', '2010-01-01 09:30:00'),
    ),
    array(
        'info' => 'Run every minute of the 8 o\'clock hour every day (* 8 * * *)',
        'job' => array('minute' => '*', 'hour' => '8', 'day_of_month' => '*', 'month' => '*', 'day_of_week' => '*'),
        'now' => $now_dates,
        'expected' => array('2010-01-01 08:00:00', '2010-01-01 08:00:00', '2010-01-01 08:00:00', '2010-01-01 08:00:00', '2010-01-02 08:00:00'),
    ),
    array(
        'info' => 'Run once a day (30 8 * * *)',
        'job' => array('minute' => '30', 'hour' => '8', 'day_of_month' => '*', 'month' => '*', 'day_of_week' => '*'),
        'now' => $now_dates,
        'expected' => array('2010-01-01 08:30:00', '2010-01-01 08:30:00', '2010-01-02 08:30:00', '2010-01-02 08:30:00', '2010-01-02 08:30:00'),
    ),
    array(
        'info' => 'Run every minute on the 20th of every month (* * 20 * *)',
        'job' => array('minute' => '*', 'hour' => '*', 'day_of_month' => '20', 'month' => '*', 'day_of_week' => '*'),
        'now' => $now_dates,
        'expected' => array('2010-01-20 00:00:00', '2010-01-20 00:00:00', '2010-01-20 00:00:00', '2010-01-20 00:00:00', '2010-01-20 00:00:00'),
    ),
    array(
        'info' => 'Run every hour on the 20th of every month (30 * 20 * *)',
        'job' => array('minute' => '30', 'hour' => '*', 'day_of_month' => '20', 'month' => '*', 'day_of_week' => '*'),
        'now' => $now_dates,
        'expected' => array('2010-01-20 00:30:00', '2010-01-20 00:30:00', '2010-01-20 00:30:00', '2010-01-20 00:30:00', '2010-01-20 00:30:00'),
    ),
    array(
        'info' => 'Run every minute of the 8 o\'clock hour on the 20th of every month (* 8 20 * *)',
        'job' => array('minute' => '*', 'hour' => '8', 'day_of_month' => '20', 'month' => '*', 'day_of_week' => '*'),
        'now' => $now_dates,
        'expected' => array('2010-01-20 08:00:00', '2010-01-20 08:00:00', '2010-01-20 08:00:00', '2010-01-20 08:00:00', '2010-01-20 08:00:00'),
    ),
    array(
        'info' => 'Run every 30th minute of the 8 o\'clock hour on the 20th of every month (30 8 20 * *)',
        'job' => array('minute' => '30', 'hour' => '8', 'day_of_month' => '20', 'month' => '*', 'day_of_week' => '*'),
        'now' => $now_dates,
        'expected' => array('2010-01-20 08:30:00', '2010-01-20 08:30:00', '2010-01-20 08:30:00', '2010-01-20 08:30:00', '2010-01-20 08:30:00'),
    ),
    array(
        'info' => 'Run every minute during the month of June(* * * 6 *)',
        'job' => array('minute' => '*', 'hour' => '*', 'day_of_month' => '*', 'month' => '6', 'day_of_week' => '*'),
        'now' => $now_dates,
        'expected' => array('2010-06-01 00:00:00', '2010-06-01 00:00:00', '2010-06-01 00:00:00', '2010-06-01 00:00:00', '2010-06-01 00:00:00'),
    ),
    array(
        'info' => 'Run once an hour during the month of June (30 * * 6 *)',
        'job' => array('minute' => '30', 'hour' => '*', 'day_of_month' => '*', 'month' => '6', 'day_of_week' => '*'),
        'now' => $now_dates,
        'expected' => array('2010-06-01 00:30:00', '2010-06-01 00:30:00', '2010-06-01 00:30:00', '2010-06-01 00:30:00', '2010-06-01 00:30:00'),
    ),
    array(
        'info' => 'Run every minute of the 8 o\'clock hour every day during the month of June (* 8 * 6 *)',
        'job' => array('minute' => '*', 'hour' => '8', 'day_of_month' => '*', 'month' => '6', 'day_of_week' => '*'),
        'now' => $now_dates,
        'expected' => array('2010-06-01 08:00:00', '2010-06-01 08:00:00', '2010-06-01 08:00:00', '2010-06-01 08:00:00', '2010-06-01 08:00:00'),
    ),
    array(
        'info' => 'Run once a day during the month of June (30 8 * 6 *)',
        'job' => array('minute' => '30', 'hour' => '8', 'day_of_month' => '*', 'month' => '6', 'day_of_week' => '*'),
        'now' => $now_dates,
        'expected' => array('2010-06-01 08:30:00', '2010-06-01 08:30:00', '2010-06-01 08:30:00', '2010-06-01 08:30:00', '2010-06-01 08:30:00'),
    ),
    array(
        'info' => 'Run every minute on the 20th during the month of June (* * 20 6 *)',
        'job' => array('minute' => '*', 'hour' => '*', 'day_of_month' => '20', 'month' => '6', 'day_of_week' => '*'),
        'now' => $now_dates,
        'expected' => array('2010-06-20 00:00:00', '2010-06-20 00:00:00', '2010-06-20 00:00:00', '2010-06-20 00:00:00', '2010-06-20 00:00:00'),
    ),
    array(
        'info' => 'Run every 30th minute on the 20th during the month of June (30 * 20 6 *)',
        'job' => array('minute' => '30', 'hour' => '*', 'day_of_month' => '20', 'month' => '6', 'day_of_week' => '*'),
        'now' => $now_dates,
        'expected' => array('2010-06-20 00:30:00', '2010-06-20 00:30:00', '2010-06-20 00:30:00', '2010-06-20 00:30:00', '2010-06-20 00:30:00'),
    ),
    array(
        'info' => 'Run every minute of the 8 o\'clock hour on the 20th during the month of June (* 8 20 6 *)',
        'job' => array('minute' => '*', 'hour' => '8', 'day_of_month' => '20', 'month' => '6', 'day_of_week' => '*'),
        'now' => $now_dates,
        'expected' => array('2010-06-20 08:00:00', '2010-06-20 08:00:00', '2010-06-20 08:00:00', '2010-06-20 08:00:00', '2010-06-20 08:00:00'),
    ),
    array(
        'info' => 'Run every 30th minute of the 8 o\'clock hour on the 20th during the month of June (30 8 20 6 *)',
        'job' => array('minute' => '30', 'hour' => '8', 'day_of_month' => '20', 'month' => '6', 'day_of_week' => '*'),
        'now' => $now_dates,
        'expected' => array('2010-06-20 08:30:00', '2010-06-20 08:30:00', '2010-06-20 08:30:00', '2010-06-20 08:30:00', '2010-06-20 08:30:00'),
    ),
    array(
        'info' => 'Run every minute on Thursday\'s (* * * * 4)',
        'job' => array('minute' => '*', 'hour' => '*', 'day_of_month' => '*', 'month' => '*', 'day_of_week' => '4'),
        'now' => $now_dates,
        'expected' => array('2010-01-07 00:00:00', '2010-01-07 00:00:00', '2010-01-07 00:00:00', '2010-01-07 00:00:00', '2010-01-07 00:00:00'),
    ),
    array(
        'info' => 'Run once an hour on Thursday\'s (30 * * * 4)',
        'job' => array('minute' => '30', 'hour' => '*', 'day_of_month' => '*', 'month' => '*', 'day_of_week' => '4'),
        'now' => $now_dates,
        'expected' => array('2010-01-07 00:30:00', '2010-01-07 00:30:00', '2010-01-07 00:30:00', '2010-01-07 00:30:00', '2010-01-07 00:30:00'),
    ),
    array(
        'info' => 'Run every minute of the 8 o\'clock hour on Thursday\'s (* 8 * * 4)',
        'job' => array('minute' => '*', 'hour' => '8', 'day_of_month' => '*', 'month' => '*', 'day_of_week' => '4'),
        'now' => $now_dates,
        'expected' => array('2010-01-07 08:00:00', '2010-01-07 08:00:00', '2010-01-07 08:00:00', '2010-01-07 08:00:00', '2010-01-07 08:00:00'),
    ),
    array(
        'info' => 'Run once a day on Thursday\'s (30 8 * * 4)',
        'job' => array('minute' => '30', 'hour' => '8', 'day_of_month' => '*', 'month' => '*', 'day_of_week' => '4'),
        'now' => $now_dates,
        'expected' => array('2010-01-07 08:30:00', '2010-01-07 08:30:00', '2010-01-07 08:30:00', '2010-01-07 08:30:00', '2010-01-07 08:30:00'),
    ),
    array(
        'info' => 'Run every minute on the 20th of every month that is also a Thursday (* * 20 * 4)',
        'job' => array('minute' => '*', 'hour' => '*', 'day_of_month' => '20', 'month' => '*', 'day_of_week' => '4'),
        'now' => $now_dates,
        'expected' => array('2010-05-20 00:00:00', '2010-05-20 00:00:00', '2010-05-20 00:00:00', '2010-05-20 00:00:00', '2010-05-20 00:00:00'),
    ),
    array(
        'info' => 'Run every 30th minute on the 20th of every month that is also a Thursday (30 * 20 * 4)',
        'job' => array('minute' => '30', 'hour' => '*', 'day_of_month' => '20', 'month' => '*', 'day_of_week' => '4'),
        'now' => $now_dates,
        'expected' => array('2010-05-20 00:30:00', '2010-05-20 00:30:00', '2010-05-20 00:30:00', '2010-05-20 00:30:00', '2010-05-20 00:30:00'),
    ),
    array(
        'info' => 'Run every minute of the 8 o\'clock hour on the 20th of every month that is also a Thursday (* 8 20 * 4)',
        'job' => array('minute' => '*', 'hour' => '8', 'day_of_month' => '20', 'month' => '*', 'day_of_week' => '4'),
        'now' => $now_dates,
        'expected' => array('2010-05-20 08:00:00', '2010-05-20 08:00:00', '2010-05-20 08:00:00', '2010-05-20 08:00:00', '2010-05-20 08:00:00'),
    ),
    array(
        'info' => 'Run every 30th minute of the 8 o\'clock hour on the 20th of every month that is also a Thursday (30 8 20 * 4)',
        'job' => array('minute' => '30', 'hour' => '8', 'day_of_month' => '20', 'month' => '*', 'day_of_week' => '4'),
        'now' => $now_dates,
        'expected' => array('2010-05-20 08:30:00', '2010-05-20 08:30:00', '2010-05-20 08:30:00', '2010-05-20 08:30:00', '2010-05-20 08:30:00'),
    ),
    array(
        'info' => 'Run every minute during the month of June on Thursday\'s (* * * 6 4)',
        'job' => array('minute' => '*', 'hour' => '*', 'day_of_month' => '*', 'month' => '6', 'day_of_week' => '4'),
        'now' => $now_dates,
        'expected' => array('2010-06-03 00:00:00', '2010-06-03 00:00:00', '2010-06-03 00:00:00', '2010-06-03 00:00:00', '2010-06-03 00:00:00'),
    ),
    array(
        'info' => 'Run once an hour during the month of June on Thursday\'s (30 * * 6 4)',
        'job' => array('minute' => '30', 'hour' => '*', 'day_of_month' => '*', 'month' => '6', 'day_of_week' => '4'),
        'now' => $now_dates,
        'expected' => array('2010-06-03 00:30:00', '2010-06-03 00:30:00', '2010-06-03 00:30:00', '2010-06-03 00:30:00', '2010-06-03 00:30:00'),
    ),
    array(
        'info' => 'Run every minute of the 8 o\'clock hour every day during the month of June on Thursday\'s (* 8 * 6 4)',
        'job' => array('minute' => '*', 'hour' => '8', 'day_of_month' => '*', 'month' => '6', 'day_of_week' => '4'),
        'now' => $now_dates,
        'expected' => array('2010-06-03 08:00:00', '2010-06-03 08:00:00', '2010-06-03 08:00:00', '2010-06-03 08:00:00', '2010-06-03 08:00:00'),
    ),
    array(
        'info' => 'Run once a day during the month of June on Thursday\'s (30 8 * 6 4)',
        'job' => array('minute' => '30', 'hour' => '8', 'day_of_month' => '*', 'month' => '6', 'day_of_week' => '4'),
        'now' => $now_dates,
        'expected' => array('2010-06-03 08:30:00', '2010-06-03 08:30:00', '2010-06-03 08:30:00', '2010-06-03 08:30:00', '2010-06-03 08:30:00'),
    ),
    array(
        'info' => 'Run every minute on the 20th during the month of June on Thursday\'s (* * 20 6 4)',
        'job' => array('minute' => '*', 'hour' => '*', 'day_of_month' => '20', 'month' => '6', 'day_of_week' => '4'),
        'now' => $now_dates,
        'expected' => array(date('Y-m-d H:i:s', sfConfig::get('app_sfCronManagerPlugin_timestamp_max')), date('Y-m-d H:i:s', sfConfig::get('app_sfCronManagerPlugin_timestamp_max')), date('Y-m-d H:i:s', sfConfig::get('app_sfCronManagerPlugin_timestamp_max')), date('Y-m-d H:i:s', sfConfig::get('app_sfCronManagerPlugin_timestamp_max')), date('Y-m-d H:i:s', sfConfig::get('app_sfCronManagerPlugin_timestamp_max'))),
    ),
    array(
        'info' => 'Run every 15th minute on the 20th during the month of June on Thursday\'s (15 * 20 6 4)',
        'job' => array('minute' => '15', 'hour' => '*', 'day_of_month' => '20', 'month' => '6', 'day_of_week' => '4'),
        'now' => $now_dates,
        'expected' => array(date('Y-m-d H:i:s', sfConfig::get('app_sfCronManagerPlugin_timestamp_max')), date('Y-m-d H:i:s', sfConfig::get('app_sfCronManagerPlugin_timestamp_max')), date('Y-m-d H:i:s', sfConfig::get('app_sfCronManagerPlugin_timestamp_max')), date('Y-m-d H:i:s', sfConfig::get('app_sfCronManagerPlugin_timestamp_max')), date('Y-m-d H:i:s', sfConfig::get('app_sfCronManagerPlugin_timestamp_max'))),
    ),
    array(
        'info' => 'Run every minute of the 8 o\'clock hour on the 20th during the month of June on Thursday\'s (* 8 20 6 4)',
        'job' => array('minute' => '*', 'hour' => '8', 'day_of_month' => '20', 'month' => '6', 'day_of_week' => '4'),
        'now' => $now_dates,
        'expected' => array(date('Y-m-d H:i:s', sfConfig::get('app_sfCronManagerPlugin_timestamp_max')), date('Y-m-d H:i:s', sfConfig::get('app_sfCronManagerPlugin_timestamp_max')), date('Y-m-d H:i:s', sfConfig::get('app_sfCronManagerPlugin_timestamp_max')), date('Y-m-d H:i:s', sfConfig::get('app_sfCronManagerPlugin_timestamp_max')), date('Y-m-d H:i:s', sfConfig::get('app_sfCronManagerPlugin_timestamp_max'))),
    ),
    array(
        'info' => 'Run every 15th minute of the 8 o\'clock hour on the 20th during the month of June on Thursday\'s (15 8 20 6 4)',
        'job' => array('minute' => '15', 'hour' => '8', 'day_of_month' => '20', 'month' => '6', 'day_of_week' => '4'),
        'now' => $now_dates,
        'expected' => array(date('Y-m-d H:i:s', sfConfig::get('app_sfCronManagerPlugin_timestamp_max')), date('Y-m-d H:i:s', sfConfig::get('app_sfCronManagerPlugin_timestamp_max')), date('Y-m-d H:i:s', sfConfig::get('app_sfCronManagerPlugin_timestamp_max')), date('Y-m-d H:i:s', sfConfig::get('app_sfCronManagerPlugin_timestamp_max')), date('Y-m-d H:i:s', sfConfig::get('app_sfCronManagerPlugin_timestamp_max'))),
    ),
);

$specials = array(
    //	Special cases
    array(
        'info' => 'Run every 30th of the month at midnight, next run in February(0 0 30 * *)',
        'job' => array('minute' => '0', 'hour' => '0', 'day_of_month' => '30', 'month' => '*', 'day_of_week' => '*'),
        'now' => array(getdate(strtotime('2010-01-30 00:00:00'))),
        'expected' => array('2010-03-30 00:00:00'),
    ),
    array(
        'info' => 'Run on the 3rd, 5th, 10th, and 12th through 24th minutes (step 2) of the 2nd hour of each day (3,5,10,12-24/2 2 * * *)',
        'job' => array('minute' => '3,5,10,12-24/2', 'hour' => '2', 'day_of_month' => '*', 'month' => '*', 'day_of_week' => '*'),
        'now' => array(getdate(strtotime('2010-01-01 02:15:00'))),
        'expected' => array('2010-01-01 02:16:00'),
    ),
    array(
        'info' => 'Run on the 3rd, 5th, and 10th minute of the 2nd hour of each day (3,5,10 2 * * *)',
        'job' => array('minute' => '3,5,10', 'hour' => '2', 'day_of_month' => '*', 'month' => '*', 'day_of_week' => '*'),
        'now' => array(getdate(strtotime('2010-01-01 02:02:00'))),
        'expected' => array('2010-01-01 02:03:00'),
    ),
    array(
        'info' => 'Run on the 3rd, 5th, and 10th minute of the 2nd hour of each day (3,5,10 2 * * *)',
        'job' => array('minute' => '3,5,10', 'hour' => '2', 'day_of_month' => '*', 'month' => '*', 'day_of_week' => '*'),
        'now' => array(getdate(strtotime('2010-01-01 02:04:00'))),
        'expected' => array('2010-01-01 02:05:00'),
    ),
    array(
        'info' => 'Run on the 3rd, 5th, and 10th minute of the 2nd hour of each day (3,5,10 2 * * *)',
        'job' => array('minute' => '3,5,10', 'hour' => '2', 'day_of_month' => '*', 'month' => '*', 'day_of_week' => '*'),
        'now' => array(getdate(strtotime('2010-01-01 02:07:00'))),
        'expected' => array('2010-01-01 02:10:00'),
    ),
    array(
        'info' => 'Run on the 3rd through the 10th minute of the 2nd hour of each day (3-10 2 * * *)',
        'job' => array('minute' => '3-10', 'hour' => '2', 'day_of_month' => '*', 'month' => '*', 'day_of_week' => '*'),
        'now' => array(getdate(strtotime('2010-01-01 02:07:00'))),
        'expected' => array('2010-01-01 02:08:00'),
    ),
    //	Error cases
    array(
        'info' => 'Run at 8:15am every day, starting from 2011-01-14 00:30 (15 8 * * *)',
        'job' => array('minute' => '15', 'hour' => '8', 'day_of_month' => '*', 'month' => '*', 'day_of_week' => '*'),
        'now' => array(getdate(strtotime('2011-01-14 00:00:00'))),
        'expected' => array('2011-01-14 08:15:00'),
    ),
    array(
        'info' => 'Run at 8:30am every Sunday in June, starting from 2011-01-18 10:14:00 (30 8 * 6 0)',
        'job' => array('minute' => '30', 'hour' => '8', 'day_of_month' => '*', 'month' => '6', 'day_of_week' => '0'),
        'now' => array(getdate(strtotime('2011-01-18 10:14:00'))),
        'expected' => array('2011-06-05 08:30:00'),
    ),
    array(
        'info' => 'Run at 8:30am every Monday in June, starting from 2011-01-18 10:14:00 (30 8 * 6 1)',
        'job' => array('minute' => '30', 'hour' => '8', 'day_of_month' => '*', 'month' => '6', 'day_of_week' => '1'),
        'now' => array(getdate(strtotime('2011-01-18 10:14:00'))),
        'expected' => array('2011-06-06 08:30:00'),
    ),
    array(
        'info' => 'Run at 8:30am every Tuesday in June, starting from 2011-01-18 10:14:00 (30 8 * 6 2)',
        'job' => array('minute' => '30', 'hour' => '8', 'day_of_month' => '*', 'month' => '6', 'day_of_week' => '2'),
        'now' => array(getdate(strtotime('2011-01-18 10:14:00'))),
        'expected' => array('2011-06-07 08:30:00'),
    ),
    array(
        'info' => 'Run at 8:30am every Wednesday in June, starting from 2011-01-18 10:14:00 (30 8 * 6 3)',
        'job' => array('minute' => '30', 'hour' => '8', 'day_of_month' => '*', 'month' => '6', 'day_of_week' => '3'),
        'now' => array(getdate(strtotime('2011-01-18 10:14:00'))),
        'expected' => array('2011-06-01 08:30:00'),
    ),
    array(
        'info' => 'Run at 8:30am every Thursday in June, starting from 2011-01-18 10:14:00 (30 8 * 6 4)',
        'job' => array('minute' => '30', 'hour' => '8', 'day_of_month' => '*', 'month' => '6', 'day_of_week' => '4'),
        'now' => array(getdate(strtotime('2011-01-18 10:14:00'))),
        'expected' => array('2011-06-02 08:30:00'),
    ),
    array(
        'info' => 'Run at 8:30am every Friday in June, starting from 2011-01-18 10:14:00 (30 8 * 6 5)',
        'job' => array('minute' => '30', 'hour' => '8', 'day_of_month' => '*', 'month' => '6', 'day_of_week' => '5'),
        'now' => array(getdate(strtotime('2011-01-18 10:14:00'))),
        'expected' => array('2011-06-03 08:30:00'),
    ),
    array(
        'info' => 'Run at 8:30am every Saturday in June, starting from 2011-01-18 10:14:00 (30 8 * 6 6)',
        'job' => array('minute' => '30', 'hour' => '8', 'day_of_month' => '*', 'month' => '6', 'day_of_week' => '6'),
        'now' => array(getdate(strtotime('2011-01-18 10:14:00'))),
        'expected' => array('2011-06-04 08:30:00'),
    ),
    array(
        'info' => 'Run at 8:30am every Sunday in June, starting from 2011-01-18 10:14:00 (30 8 * 6 7)',
        'job' => array('minute' => '30', 'hour' => '8', 'day_of_month' => '*', 'month' => '6', 'day_of_week' => '7'),
        'now' => array(getdate(strtotime('2011-01-18 10:14:00'))),
        'expected' => array('2011-06-05 08:30:00'),
    ),
);

$ready_to_run = array(
    array(
        'info' => 'Check to see if I run at this time, my job is (*/15 * * * *)',
        'job' => array('minute' => '*/15', 'hour' => '*', 'day_of_month' => '*', 'month' => '*', 'day_of_week' => '*'),
        'now' => array(getdate(strtotime('2011-02-25 19:50:00')),getdate(strtotime('2011-02-25 19:55:00')),getdate(strtotime('2011-02-25 20:00:00'))),
        'expected' => array(false, false, true),
    ),
);

$expansions = array(
    array(
        'info' => 'Expand 5',
        'expansion' => '5',
		'start' => 0,
		'end' => 59,
        'expected' => array(5),
    ),
    array(
        'info' => 'Expand 0-30',
        'expansion' => '0-30',
		'start' => 0,
		'end' => 59,
        'expected' => range(0, 30),
    ),
    array(
        'info' => 'Expand 0,15,30,45',
        'expansion' => '0,15,30,45',
		'start' => 0,
		'end' => 59,
        'expected' => array(0, 15, 30, 45),
    ),
    array(
        'info' => 'Expand 5-59/10',
        'expansion' => '5-59/10',
		'start' => 0,
		'end' => 59,
        'expected' => array(5, 15, 25, 35, 45, 55),
    ),
    array(
        'info' => 'Expand 5,10,15,35-55/10,27-37/2',
        'expansion' => '5,10,15,35-55/10,27-37/2',
		'start' => 0,
		'end' => 59,
        'expected' => array(5, 10, 15, 27, 29, 31, 33, 35, 37, 45, 55),
    ),
    array(
        'info' => 'Expand *',
        'expansion' => '*',
		'start' => 0,
		'end' => 59,
        'expected' => range(0,59),
    ),
    array(
        'info' => 'Expand */15',
        'expansion' => '*/15',
		'start' => 0,
		'end' => 59,
        'expected' => array(0, 15, 30, 45),
    ),
);

$cm = new CronManagerDoctrine;

$t = new lime_test(count($tests) * count($now_dates) + count($specials) + count($ready_to_run) * count($ready_to_run[0]['expected']) + count($expansions));

//	Now that that count is calculated, add the special tests into the rest
$tests = array_merge($tests, $specials);

$t->info(dirname(__FILE__) . '/../bootstrap/unit.php');
$t->info('Beginning tests...');
foreach($tests as $test)
{
  foreach($test['now'] as $idx => $now)
  {
    $date = $cm->getNextRunDate($test['job'], $now);
    $t->info($test['info'] . ', today is ' . date('Y-m-d H:i:s', $now[0]));
    $t->is($date, $test['expected'][$idx]);
  }
}

foreach($ready_to_run as $test)
{
  foreach($test['now'] as $idx => $now)
  {
    $ready = $cm->isReadyByTime($test['job'], $now);
    $t->info($test['info'] . ', today is ' . date('Y-m-d H:i:s', $now[0]));
    $t->is($ready, $test['expected'][$idx]);
  }
}

foreach($expansions as $test)
{
    $expansion = $cm->expand($test['expansion'], $test['start'], $test['end']);
    $t->info($test['info']);
    $t->is($expansion, $test['expected']);
}